﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Tenebrous_Manor
{

    class Credits
    {
        Texture2D blank;
        SpriteFont font;
        int textPosition;
        int screenHeight;
        int screenWidth;
        int position;
        int line_space = 45;
        int num_names;
        String currentStr;

        
        String credits = "Credits";
        String developer = "Developers";
        String artist = "Artist";
        String playTester = "QA Testers";
        String sound = "Sound Designers";
        String thanks = "Thanks for playing!";
       
        int roleCount = 5;

        String richard = "Richard Wou";
        String cassie = "Cassie Wong";
        String michael = "Michael McDougall";
        String denis = "Denis Kamtchatnikov";


        public Credits(Texture2D blank, SpriteFont font, int screenWidth, int screenHeight)
        {
            this.blank = blank;
            this.font = font;
            this.screenHeight = screenHeight;
            this.screenWidth = screenWidth;

            position = screenHeight;
        }

        public void Update(GameTime gameTime)
        {
            if (position <= -650)
            {
                position = -650;
            }
            else
            {
                position -= 2;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            //spriteBatch.Draw(blank, new Rectangle(0, 0, screenWidth, screenHeight), Color.Black);

            drawString(spriteBatch, credits, 0);

            drawString(spriteBatch, developer, 2);
            drawString(spriteBatch, richard, 3);
            drawString(spriteBatch, cassie, 4);
            drawString(spriteBatch, michael, 5);
            drawString(spriteBatch, denis, 6);

            drawString(spriteBatch, artist, 8);
            drawString(spriteBatch, denis, 9);

            drawString(spriteBatch, sound, 11);
            drawString(spriteBatch, michael, 12);
            drawString(spriteBatch, denis, 13);

            drawString(spriteBatch, thanks, 22);

            /*
            for (int i = 0; i < roleCount; i++)
            {  
                currentStr = getRole(i);
                num_names = getNum_Names(i);
                textPosition = getTextPosition(currentStr);
                //position += line_space * 2;
                spriteBatch.DrawString(font, currentStr, new Vector2(textPosition, position), Color.White);

                for (int j = 0; j < num_names; j++)
                {
                    //position -= line_space;
                    currentStr = getName(i, j);
                    textPosition = getTextPosition(currentStr);
                    
                    spriteBatch.DrawString(font, currentStr, new Vector2(textPosition, position), Color.White);
                    position += line_space;
                }
            }
             * */
        }

        public void drawString(SpriteBatch spriteBatch, string name, int mult)
        {
            textPosition = getTextPosition(name);
            spriteBatch.DrawString(font, name, new Vector2(textPosition, position + mult * line_space), Color.White);
        }

        public void reset()
        {
            position = screenHeight;
        }

        public int getTextPosition(string word)
        {
            return (screenWidth - (int)font.MeasureString(word).X) / 2;
        }

        public String getRole(int i)
        {
            switch (i)
            {
                case 0:
                    return credits;
                case 1:
                    return developer;
                case 2:
                    return artist;
                case 3:
                    return sound;
                default :
                    return playTester;
            }
        }

        public int getNum_Names(int i)
        {
            switch (i)
            {
                case 0:
                    return 0;
                case 1:
                    return 3;
                case 2:
                    return 1;
                case 3:
                    return 2;
                default:
                    return 4;
            }
        }

        public string getName(int i, int j)
        {
            switch (i)
            {
                case 0 :
                        return "";
                    break;
                case 1 :
                    if (j == 0)
                        return cassie;
                    else if (j == 1)
                        return richard;
                    else if (j == 2)
                        return michael;
                    else
                        return denis;
                    break;
                case 2 :
                        return denis;
                    break;
                case 3 :
                    if (j == 0)
                        return michael;
                    else
                        return denis;
                default : 
                    if (j == 0)
                        return cassie;
                    else if (j == 1)
                        return richard;
                    else if (j == 2)
                        return michael;
                    else
                        return denis;
                    break;
            }
        }
    }
}
